package com.evil.application.enums.reporting;

import cn.hutool.core.map.MapUtil;
import com.evil.common.core.enums.RCodeEnum;
import com.evil.common.core.exception.BusinessException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 报表样式类型
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@AllArgsConstructor
public enum ReportingStyleTypeEnum {

    /**
     * 报表样式类型
     */
    DEFAULT(0, "默认"),
    BLUE_ORANGE(1, "蓝橙撞色"),
    WINE_RED(2, "英伦酒红"),
    GRASS_GREEN(3, "清新草绿"),
    PURPLE(4, "神秘魅紫"),
    WARM_SUN(5, "热情暖阳"),
    ;

    @Getter
    private final int id;
    @Getter
    private final String name;

    public static Optional<ReportingStyleTypeEnum> findById(Integer id) {
        if (Objects.isNull(id)) {
            return Optional.empty();
        }
        return Arrays.stream(values()).filter(e -> e.id == id).findFirst();
    }

    public static ReportingStyleTypeEnum isExistById(Integer id) {
        return ReportingStyleTypeEnum.findById(id).orElseThrow(ReportingStyleTypeEnum::getBusinessException);
    }

    public static Stream<ReportingStyleTypeEnum> getStream() {
        return Arrays.stream(values());
    }

    public static List<Map<Integer, String>> types() {
        return ReportingStyleTypeEnum.getStream().map(e -> MapUtil.of(e.id, e.name)).collect(Collectors.toList());
    }

    public static BusinessException getBusinessException() {
        return new BusinessException(RCodeEnum.ERROR_PARAMETER, "报表样式类型参数错误");
    }
}
